home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / pbaseiv.zip / P4UTL001.TIP < prev    next >
Text File  |  1991-12-16  |  3KB  |  72 lines

  1. I frequently want my batch files to know whether a DOS
  2. program is running from within a Windows DOS virtual machine
  3. or from the DOS prompt alone. According to Microsoft, it's
  4. dangerous to run certain programs, such as CHKDSK, while
  5. you're in Windows. I also need to write batch files that
  6. display a message telling the user how to switch back to
  7. Windows with a hot key.
  8.  
  9. I discovered that when Windows is running, it creates an
  10. environment variable with the name `windir' that points to
  11. the Windows directory. Normally, one can test for variables
  12. with the `==' operator, but `==' assumes that variable names
  13. are all uppercase, and `windir' is lowercase. (Microsoft
  14. probably did this so the SET command couldn't create or
  15. change the variable.) Any reference to `windir' in a batch
  16. file actually looks for a variable named `WINDIR,' which
  17. isn't the same thing.
  18.  
  19. To circumvent this problem, I wrote a small assembly
  20. language program that searches for `windir.' If it's found,
  21. the program returns an ERRORLEVEL of 1; otherwise it returns
  22. an ERRORLEVEL of 0. I called the program InWinEQ1, which is
  23. a mnemonic for "In Windows Equals 1." CHKDSK.BAT [below]
  24. shows how you can use InWinEQ1 to prevent users from running
  25. CHKDSK from within Windows. First, put CHKDSK.BAT and
  26. INWINEQ1.COM in a directory listed in your PATH command and
  27. rename your DOS directory's CHKDSK.COM to CHKDSK!.COM
  28. (depending on your DOS version, CHKDSK may be an EXE
  29. program). When a user types CHKDSK, the batch file will
  30. check to see if Windows is running. If it is, InWinEQ1 will
  31. return an ERRRORLEVEL of 1, and the batch file will go
  32. directly to the :INWINDOWS line, skipping the CHKDSK!
  33. command. You can easily modify this batch file for other
  34. purposes.
  35.  
  36. Christopher J. Stein
  37. Durham, North Carolina
  38.  
  39. Editor's note: The Windows documentation says that running
  40. CHKDSK, SUBST, JOIN, FASTOPEN, or ASSIGN in a Windows DOS
  41. virtual machine can cause major problems, but Microsoft does
  42. nothing to prevent this from happening. Mr. Stein's
  43. technique makes sure you don't lock up your machine--or
  44. worse, corrupt your disk.
  45.  
  46. InWinEQ1 is included, in executable form, in the P4UTIL
  47. directory on your PowerBase *.* Volume IV diskette. To use
  48. it, copy it to any directory on your PATH. You can copy the
  49. sample listing in this tip to a file by pressing the Alt-F
  50. key.
  51.  
  52.  
  53. CHKDSK.BAT -- A demonstration of InWinEQ1
  54.  
  55. ---- BEGIN LISTING ----
  56. @ECHO OFF
  57. InWinEQ1
  58. IF ERRORLEVEL 1 GOTO INWINDOWS
  59. CHKDSK! %1 %2 %3
  60. GOTO DONE
  61. :INWINDOWS
  62. ECHO You cannot run CHKDSK from inside Windows!
  63. :DONE
  64. ECHO ON
  65. ---- END LISTING ----
  66.  
  67. Title: Am I Weally in Windows?
  68. Category: MSC
  69. Issue date: Dec 1991
  70. Editor: Brett Glass
  71. Supplementary files: P4UTIL\INWINEQ1.COM
  72.